# your_app_name/models.py

from django.db import models
from django.utils import timezone
import uuid


class User(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    phone_number = models.CharField(max_length=15, unique=True, null=True, verbose_name='手机号')
    avatar_url = models.URLField(blank=True, null=True, verbose_name='头像URL地址')
    user_type = models.IntegerField(blank=True, null=True, verbose_name='用户类型')
    nickname = models.CharField(max_length=100, verbose_name='昵称')
    email = models.EmailField(blank=True, null=True, verbose_name='邮箱')
    gender = models.IntegerField(blank=True, null=True, verbose_name='性别')
    birth_date = models.CharField(max_length=255, verbose_name='生日', null=True)
    province = models.IntegerField(blank=True, null=True, verbose_name='省')
    city = models.IntegerField(blank=True, null=True, verbose_name='市')
    district = models.IntegerField(blank=True, null=True, verbose_name='区')
    address = models.CharField(max_length=255, blank=True, null=True, verbose_name='详细地址')
    ip_address = models.CharField(max_length=255, blank=True, null=True, verbose_name='IP地址')
    points = models.IntegerField(default=0, verbose_name='积分')
    bio = models.TextField(blank=True, null=True, verbose_name='个人简介')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = '用户'
        db_table = 'db_user'


class Dictionary(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    added_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='添加人ID')
    name = models.CharField(max_length=100, verbose_name='名称')
    icon_url = models.CharField(blank=True, null=True, max_length=255, verbose_name='ICO URL')
    type = models.CharField(max_length=100, verbose_name='类型')
    code = models.IntegerField(blank=True, null=True, verbose_name='编码')
    color = models.CharField(max_length=100, verbose_name='颜色值')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        db_table = 'db_dictionary'
        verbose_name = '字典'
        verbose_name_plural = '字典'


class SMSVerification(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    phone_number = models.CharField(max_length=20, verbose_name='手机号')
    code = models.CharField(max_length=6, verbose_name='验证码')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')

    class Meta:
        db_table = "db_SMSVerification"
        verbose_name = '短信验证码'
        verbose_name_plural = '短信验证码'


class Category(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    added_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='添加人ID')
    title = models.CharField(max_length=100, verbose_name='标题')
    description = models.TextField(blank=True, null=True, verbose_name='描述')
    img_url = models.CharField(blank=True, null=True, max_length=255, verbose_name='图片URL')
    type = models.IntegerField(blank=True, null=True, verbose_name='类型')
    parent_id = models.UUIDField(blank=True, null=True, verbose_name='父分类ID')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        db_table = "db_category"
        verbose_name = '分类'
        verbose_name_plural = '分类'


class Resource(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    added_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True, verbose_name='添加人ID')
    category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='资源所属的分类')
    title = models.CharField(max_length=100, verbose_name='标题')
    description = models.TextField(blank=True, null=True, verbose_name='描述')
    link = models.CharField(max_length=255, blank=True, null=True, verbose_name='链接')
    thumbnail = models.CharField(blank=True, null=True, max_length=255, verbose_name='缩略图')
    rich_text = models.TextField(blank=True, null=True, verbose_name='富文本')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        db_table = "db_resource"
        verbose_name = '资源'
        verbose_name_plural = '资源'


class ArticleBlog(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    added_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True, verbose_name='添加人ID')
    category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='资源所属的分类')
    title = models.CharField(max_length=100, verbose_name='标题')
    description = models.TextField(blank=True, null=True, verbose_name='描述')
    thumbnail = models.CharField(blank=True, null=True, max_length=255, verbose_name='缩略图')
    click_through_rate = models.CharField(max_length=100, blank=True, null=True, verbose_name='点击率')
    rich_text = models.TextField(blank=True, null=True, verbose_name='富文本')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        db_table = "db_article-blog"
        verbose_name = '文章博客'
        verbose_name_plural = '文章博客'


class SiteInclusion(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name='ID')
    added_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True, verbose_name='添加人ID')
    type = models.IntegerField(blank=True, null=True, verbose_name='是否已收录')
    category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='站点所属的分类')
    name = models.CharField(blank=True, null=True, max_length=100, verbose_name='站点名称')
    link = models.CharField(blank=True, null=True, max_length=100, verbose_name='站点地址')
    description = models.TextField(blank=True, null=True, verbose_name='站点简介')
    email = models.EmailField(blank=True, null=True, verbose_name='邮箱')
    phone_number = models.CharField(max_length=15, null=True, verbose_name='手机号')
    nickname = models.CharField(blank=True, null=True, max_length=100, verbose_name='昵称')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建日期')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='修改日期')

    class Meta:
        db_table = "db_site-inclusion"
        verbose_name = '站点收录'
        verbose_name_plural = '站点收录'
